home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / PolySelectConvert.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  5.1 KB  |  180 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  28 December 1999
  22. //
  23. //  Description:
  24. //      This implements the Polygon and Subdiv selection
  25. //        conversion operation.
  26. //
  27.  
  28. global proc PolySelectConvert(int $toType)
  29. {
  30.     string    $converted[];
  31.     string    $convertedSubd[];
  32.     int        $numConvertedSubdFaces = 0;
  33.     string    $tokens[];
  34.     string    $evalStr;
  35.     string    $selList[];
  36.     string    $addToSelList[];
  37.     int        $i;
  38.  
  39.     if( `isTrue "SubdivUIExists"` ) {
  40.         //
  41.         // First replace all subd shapes (or their transforms)
  42.         // in the selection list with
  43.         // all their faces at the current display level.
  44.         // This is necessary because subd component conversion only occurs
  45.         // among component selection types.
  46.         //
  47.         $selList = `ls -sl`;
  48.         int $numSelected = size($selList);
  49.         string $selType[];
  50.         string    $subdivShapesToConvert[];
  51.         string    $itemsToDeselect[];
  52.         string    $children[];
  53.         string    $childType[];
  54.         int            $numChildren;
  55.         int            $child;
  56.         int            $found;
  57.         int            $numToConvert = 0;
  58.         int            $numToDeselect = 0;
  59.         int            $isIntermediate = 0;
  60.  
  61.         //
  62.         // Take a pass through the selection list, keepting track of
  63.         // subdiv shapes found (they need to be replaced with a list
  64.         // of all their faces at the current display level).
  65.         // For those that are represented by their transform parent,
  66.         // keep a list of those, as those transfors will need to
  67.         // be removed from the selection list.
  68.         for ($i = 0; $i < $numSelected; $i++) {
  69.             $selType = `ls -st $selList[$i]`;
  70.             if ($selType[1] == "transform") {
  71.                 $children = `listRelatives -children $selList[$i]`;
  72.                 $numChildren = size($children);
  73.                 $found = 0;
  74.                 for ($child = 0; $child < $numChildren && !$found; $child++) {
  75.                     $childType = `ls -st $children[$child]`;
  76.                     if ($childType[1] == "subdiv") {
  77.                         string $getAttrCmd = "getAttr " + $children[$child]
  78.                                             + ".intermediateObject";
  79.                         $isIntermediate = eval($getAttrCmd);
  80.  
  81.                         //
  82.                         // Ignore intermediateObjects (those that
  83.                         // are the hidden inputs to a deformation).
  84.                         if ($isIntermediate == 0) {
  85.                             //
  86.                             // Add this child to the list of subdiv shapes
  87.                             // to convert to faces.
  88.                             $subdivShapesToConvert[$numToConvert]
  89.                                 = $children[$child];
  90.                             $numToConvert++;
  91.  
  92.                             $itemsToDeselect[$numToDeselect] = $selList[$i];
  93.                             $numToDeselect++;
  94.                             $found = 1;
  95.                         }
  96.                     }
  97.                 }
  98.             } else if ($selType[1] == "subdiv") {
  99.                 //
  100.                 // Add this shape to the list of subdiv shapes
  101.                 // to convert to faces.
  102.                 $subdivShapesToConvert[$numToConvert] = $selList[$i];
  103.                 $numToConvert++;
  104.                 $itemsToDeselect[$numToDeselect] = $selList[$i];
  105.                 $numToDeselect++;
  106.  
  107.             }
  108.         }
  109.         for ($i = 0; $i < $numToDeselect; $i++) {
  110.             select -toggle $itemsToDeselect[$i];
  111.         }
  112.         $selList = `ls -sl`;
  113.         for ($i = 0; $i < $numToConvert; $i++) {
  114.             querySubdiv -a 4 $subdivShapesToConvert[$i];
  115.             $addToSelList = `ls -sl`;
  116.             select $selList $addToSelList;
  117.             $selList = `ls -sl`;
  118.         }
  119.     }
  120.  
  121.     // To Face
  122.     if ($toType == 1)
  123.     {
  124.         $converted = `polyListComponentConversion -fv -fe -fuv -fvf -tf`;
  125.         $convertedSubd = `subdListComponentConversion -fv -fe -fuv -ff -tf`;
  126.     }
  127.  
  128.     // To Edge
  129.     else if ($toType == 2)
  130.     {
  131.         $converted = `polyListComponentConversion -fv -ff -fuv -fvf -te`;
  132.         $convertedSubd = `subdListComponentConversion -fv -ff -fuv -te`;
  133.     }
  134.  
  135.     // To Vertex
  136.     else if ($toType == 3)
  137.     {
  138.         $converted = `polyListComponentConversion -ff -fe -fuv -fvf -tv`;
  139.         $convertedSubd = `subdListComponentConversion -ff -fe -fuv -tv`;
  140.     }
  141.  
  142.     // To UV
  143.     else if ($toType == 4)
  144.     {
  145.         $converted = `polyListComponentConversion -fv -fe -ff -fvf -tuv`;
  146.         $convertedSubd = `subdListComponentConversion -fv -fe -ff -tuv`;
  147.     }
  148.  
  149.     
  150.     // To vertexFace 
  151.     else if ($toType == 5) 
  152.     { 
  153.         $converted = `polyListComponentConversion -fv -fe -ff -fuv -tvf`; 
  154.         //no vertex faces for subds 
  155.     }
  156.  
  157.     int    $n = size($converted);
  158.     int $ns = size($convertedSubd);
  159.     if ( ($n > 0) || ($ns > 0) )
  160.     {
  161.         $evalStr = "select -r";
  162.  
  163.         for ( $i=0; $i<$n; $i++)
  164.         {
  165.             $evalStr += " \"";
  166.             $evalStr += $converted[$i];
  167.             $evalStr += "\"";
  168.         }
  169.  
  170.         $n = size($convertedSubd);
  171.         for ( $i=0; $i<$n; $i++)
  172.         {
  173.             $evalStr += " \"";
  174.             $evalStr += $convertedSubd[$i];
  175.             $evalStr += "\"";
  176.         }
  177.         eval $evalStr;
  178.     }
  179. }
  180.